import createVanilla from 'zustand/vanilla'
import { subscribeWithSelector } from 'zustand/middleware'
import create from 'zustand'
import { ActionButtonsType } from './translator'
type StateStore = {
	/**
	 *  底部实际显示按钮集
	 */
	screenList: ActionButtonsType[]
}
type IStore = StateStore & {
	update: (d: Partial<StateStore>) => void
	reset: () => void
	switchCheckOrUnCheckAll: (replaceLabel: 'checkAll' | 'unCheckAll') => void
}
const initialState: StateStore = {
	screenList: [],
}
export const store = createVanilla<IStore>()(
	subscribeWithSelector((set, get) => ({
		...initialState,
		update: (d) => set({ ...d }),
		reset: () => set(initialState),
		switchCheckOrUnCheckAll: (replaceLabel) => {
			let list = get().screenList
			let prevLabel = replaceLabel === 'checkAll' ? 'unCheckAll' : 'checkAll'
			let _list = list.map((x) => {
				if (x === prevLabel) {
					return replaceLabel
				} else {
					return x
				}
			})
			set({
				screenList: _list,
			})
		},
	}))
)
export const useActionButtonsStore = create(store)
